package com.guyu.plugin.oss.enums;

import com.guyu.common.core.enums.able.IEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import software.amazon.awssdk.services.s3.model.BucketCannedACL;

import java.util.Objects;

/**
 * 桶访问策略配置
 */
@Getter
@AllArgsConstructor
public enum BucketAccessPolicyType implements IEnum<BucketAccessPolicyType> {

    PRIVATE(1, "私有", BucketCannedACL.PRIVATE),

    PUBLIC_READ(2, "公共读", BucketCannedACL.PUBLIC_READ),

    PUBLIC(3, "公共读写", BucketCannedACL.PUBLIC_READ_WRITE);


    /**
     * 权限类型
     */
    private final Integer code;
    private final String desc;

    /**
     * 桶 权限类型
     */
    private final BucketCannedACL bucketCannedACL;

    /**
     * 获取桶默认的文件访问策略
     */
    public ObjectAccessPolicyType getObjectCannedACL() {
        if (Objects.equals(BucketAccessPolicyType.PRIVATE, this)) {
            return ObjectAccessPolicyType.PRIVATE;
        } else if (Objects.equals(BucketAccessPolicyType.PUBLIC_READ, this)) {
            return ObjectAccessPolicyType.PUBLIC_READ;
        } else if (Objects.equals(BucketAccessPolicyType.PUBLIC, this)) {
            return ObjectAccessPolicyType.PUBLIC;
        }
        return null;
    }


    @Override
    public BucketAccessPolicyType getDefault() {
        return PRIVATE;
    }
}
